<?php
/**
 *      [Elitechmedia!] (C)2001-2099 MYSELF Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: addnew.php 22609 2013-10-16 01:55:33Z zhangchaofeng
 */
if(!isset($_SESSION)){
	session_start();
}
if(!$_SESSION['uid']){
	require_once "tmp/login.htm";exit;
}
include_once("classes/DB.class.php");
include_once("classes/page.class.php");
include_once("function/member.php");
include_once("qrlib.php");
include_once("function/function_file.php");
include_once("function/util.func.php");
date_default_timezone_set('Asia/Shanghai');
$uid=$_SESSION['uid'];
$cid=$_SESSION['c_id'];
if($cid==-1):
$message="<font color='red'>对不起你还没有自己的企业无法添加您的员工...!!</font>";
$text="如果您的浏览器没有自动跳转，请点击这里";
$url='new.php';
include 'tmp/error.htm';exit;
endif;
$id=addslashes($_REQUEST['id']);
if($id!=''):
	$info = $GLOBALS["DB"]->result("SELECT * FROM employee where uid='$id'");
	$info=$info[0];
endif;
if($_SERVER['REQUEST_METHOD'] == 'POST'):
	$data['name']=addslashes($_POST['name']);
	$upid=$_POST['upid'];
	if($data['name']!=''):
		$data['sex']=addslashes($_POST['sex']);
		$data['telphone']=addslashes($_POST['telphone']);
		$data['type']=addslashes($_POST['type']);
		if($_POST['p_no']!=''):
			$data['p_no']=addslashes($_POST['p_no']);
		else:
			$message="<font color='red'>员工编号不能为空...!!</font>";
			$text="如果您的浏览器没有自动跳转，请点击这里";
			$url='new.php';
			include 'tmp/error.htm';exit;
		endif;
		if($_SESSION['c_id']==0):
			$data['c_id']=addslashes($_POST['c_id']);
		else:
			$data['c_id']=$_SESSION['c_id'];
		endif;
		/* $path=realpath(dirname('static'));
		$up_dir_file=$path."/static/upload/";//上传目录路径
		if (!file_exists($up_dir_file)):
			if(!mkdirs($up_dir_file,0777)):
				$message="<font color='red'>对不起您没有权限创建文件夹...!</font>";
				$text="如果您的浏览器没有自动跳转，请点击这里";
				$url='new.php';
				include 'tmp/error.htm';exit;
			endif;
		endif;
		if(isset($_FILES["pic"]) && !empty($_FILES["pic"]['name'])):
			//创建新名称
			$newname = time().'.'.array_pop(explode('.',$_FILES['pic']['name']));
			//上传文件
			$e_pic_message=uploadPic('pic',$up_dir_file,$newname);
			if(empty($e_pic_message)):
				$data['pic']=$newname;
			else:
				$message="<font color='red'>图片上传失败：$errorpic</font>";
				$text="如果您的浏览器没有自动跳转，请点击这里";
				$url='new.php';
				include 'tmp/error.htm';exit;
			endif;
		endif; */
		//QR生成
		$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
		
		$PNG_WEB_DIR = 'temp/';
		
		if (!file_exists($PNG_TEMP_DIR))
			mkdir($PNG_TEMP_DIR);
		
		$errorCorrectionLevel='L';
		$matrixPointSize=7;
		if($upid!=''):
			$GLOBALS["DB"]->execute_event("update employee set ".implode_field_value($data) ." where uid='$upid'");
			$message="<font color='green'>您的操作已经成功....</font>";
			$text="如果您的浏览器没有自动跳转，请点击这里";
			$url='new.php';
			include 'tmp/success.htm';exit;
		else:
			$fid = $GLOBALS["DB"]->insert("INSERT INTO employee set ".implode_field_value($data));
			$userinfoqr=$data['c_id'].','.$data['p_no'].','.$fid;
			$filename = $PNG_TEMP_DIR.'test'.md5($userinfoqr.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
			QRcode::png($userinfoqr, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
			if(!$fid):
				$message="<font color='red'>对不起数据保存失败.!!</font>";
				$text="如果您的浏览器没有自动跳转，请点击这里";
				$url='new.php';
				include 'tmp/error.htm';exit;
			else:
				$data1['qr']='test'.md5($userinfoqr.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
				$GLOBALS["DB"]->execute_event("update employee set ".implode_field_value($data1) ." where uid='$fid'");
				$message="<font color='green'>您的操作已经成功....</font>";
				$text="如果您的浏览器没有自动跳转，请点击这里";
				$url='new.php';
				include 'tmp/success.htm';exit;
			endif;
		endif;
	else:
		$message="<font color='red'>标题不能为空...!!</font>";
		$text="如果您的浏览器没有自动跳转，请点击这里";
		$url='new.php';
		include 'tmp/error.htm';exit;
	endif;
endif;
$data_row = $GLOBALS["DB"]->result("SELECT id,c_name FROM company where 1=1 ORDER BY id DESC ");
include 'tmp/addnew.htm';